<extend name="./Application/Common/View/block/base.php" />
<block name="header">
    <include file="./Application/Admin/View/block/easyui_header.php" />
    <link href="__PUBLIC__/css/Announce/index.css" rel="stylesheet" type="text/css" />
</block>
<block name="bdoy">
    <body>
    <?php
        $nav_priv_model = D('NavPriv');
        $priv_array = $nav_priv_model->query_once_to_array($_GET['role_id']);
    ?>
    <div class="table-cont">
        <form>
            <table width="100%" cellspacing="0">
                <thead>
                <tr>
                    <th width="35" align="center">全选</th>
                    <th width="100" align="center">栏目名称</th>
                    <th width="68" align="center">增加</th>
                    <th width="68" align="center">删除</th>
                    <th width="68" align="center">修改</th>
                    <th width="50" align="center">查看</th>
                </tr>
                </thead>
                <tbody>
                <volist name="nav_list" id="nav">
                    <tr id="tr_{$nav['id']}">
                        <td width="35"><input class="id_box" id="ch_{$nav['id']}" type="checkbox" value="{$nav['id']}"/></td>
                        <td width="300" align="center">{$nav['title']}</td>
                        <td width="68"><input class="op_box" type="checkbox" id="" value="{$nav['id']},add" {:role_cat_priv_checked($priv_array, $nav['id'].',add')}/></td>
                        <td width="68"><input class="op_box" type="checkbox" id="" value="{$nav['id']},del" {:role_cat_priv_checked($priv_array, $nav['id'].',del')}/></td>
                        <td width="68"><input class="op_box" type="checkbox" id="" value="{$nav['id']},update" {:role_cat_priv_checked($priv_array, $nav['id'].',update')}/></td>
                        <td width="50"><input class="op_box" type="checkbox" id="" value="{$nav['id']},show" {:role_cat_priv_checked($priv_array, $nav['id'].',show')}/></td>
                    </tr>
                </volist>
                </tbody>
            </table>
        </form>
    </div>


    </body>
</block>
<block name="footExtendJs">
    <script>
        $(function(){
            $('.id_box').change(function(){
                var id = $(this).val();
                tr_input(id);
            });
            $('.op_box').change(function(){
                var checked = $(this).prop('checked');
                var val = $(this).val();
                if(checked=='checked' || checked){
                    add_priv(val);
                }else{
                    del_priv(val)
                }
            });
        });
        function checked_tr(id){
            $('#tr_'+id+' .op_box').each(function(index){
                $(this).prop('checked', 'checked');
                var val = $(this).val();
                add_priv(val);
            });
        }

        function no_checked_tr(id){
            $('#tr_'+id+' .op_box').each(function(index){
                $(this).removeProp('checked');
                var val = $(this).val();
                del_priv(val);
            });
        }

        function tr_input(id){
            var checked = $('#ch_'+id).prop('checked');
            if(checked){
                checked_tr(id);
            }else{
                no_checked_tr(id);
            }
        }

        function add_priv(val){
            var role = {$_GET['role_id']};
            var url = '__URL__/add_role_cat_priv?role_id='+role+'&&val='+val;
            $.get(url, function(){

            });
        }

        function del_priv(val){
            var role = {$_GET['role_id']};
            var url = '__URL__/del_role_cat_priv?role_id='+role+'&&val='+val;
            $.get(url, function(){

            });
        }

    </script>
</block>
